<template>
	<view class="detail">
		<swiper autoplay indicator-dots>
			<swiper-item v-for="item in ImageList">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<view class="goodsPrice">
			<view class="price">
				<text>￥{{goodinfo.sell_price}}</text>
				<text class="old">￥{{goodinfo.market_price}}</text>
			</view>
			<view class="name">
				{{goodinfo.title}}
			</view>
		</view>
		<view class="line"></view>
		<view class="Num">
			<view>
				货号：{{goodinfo.goods_no}}
			</view>
			<view>
				库存：{{goodinfo.stock_quantity}}
			</view>
		</view>
		<view class="line"></view>
		<view class="info">
			<view class="title">
				详情介绍
			</view>
			<view class="content">
				<rich-text :nodes="gooddesc.content"></rich-text>
			</view>
		</view>
		<uni-goods-nav class='goods-nav' :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
			@buttonClick="buttonClick" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				goodinfo: {},
				gooddesc: {},
				ImageList: [{
					img: "https://www.ssfiction.com/wp-content/uploads/2020/08/20200805_5f2b1669e9a24.jpg"
				}, {
					img: "https://img1.baidu.com/it/u=1308526554,393095433&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800"
				}, {
					img: "https://img2.baidu.com/it/u=1939173783,548367781&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"
				}],
				options: [{
					icon: 'headphones',
					text: '客服'
				}, {
					icon: 'shop',
					text: '店铺',
					info: 0,
					infoBackgroundColor: '#007aff',
					infoColor: "red"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 2
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			};
		},
		onLoad(op) {
			this.id = op.id
			this.getinfo(this.id)
			this.getdesc(this.id)
		},
		methods: {
			async getinfo(id) {
				const res = await this.$myRequest({
					url: "/api/goods/getinfo/" + id
				})
				this.goodinfo = res.data.message[0]
			},
			async getdesc(id) {
				const res = await this.$myRequest({
					url: "/api/goods/getdesc/" + id
				})
				this.gooddesc = res.data.message[0]
			},
			onClick(e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
				this.options[2].info++
			}
		}
	}
</script>

<style lang="scss">
	.detail {
		swiper {
			width: 750rpx;
			height: 600rpx;

			swiper-item {
				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.goodsPrice {
			font-size: 32rpx;
			padding: 5px 10px 8px 8px;

			.price {
				color: $shop-color;
				line-height: 40px;

				.old {
					padding-left: 15px;
					color: #ccc;
					font-size: 28rpx;
					text-decoration: line-through;
				}
			}

		}

		.line {
			width: 100%;
			height: 6px;
			background-color: #eee;
		}

		.Num {
			padding: 5px 10px 8px 8px;
			line-height: 30px;
		}

		.info {
			font-size: 30rpx;

			.title {
				padding-left: 8px;
				font-size: 32rpx;
				line-height: 35px;
				border-bottom: 1px solid #eee;
			}

			.content {
				padding-top: 10px;
				padding: 0 8px;
				line-height: 2;
				padding-bottom: 50px;
			}
		}

		.goods-nav {
			position: fixed;
			bottom: 0;
			width: 100%;
		}
	}
</style>
